package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
   servlet处理类

   自调用方法

   完成需求:一个servlet实现多个功能
   通过传参方式
 */
/*@WebServlet("/DemoServlet")*/
public class DemoServlet extends HttpServlet {
    /*
        service  既可以接收get也可以接收post
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if ("findAll".equals(method)) {
            findAll(req, resp);
        } else if ("save".equals(method)) {
            save(req, resp);
        } else if ("update".equals(method)) {
            update(req, resp);
        }

        System.out.println("save....");
    }

    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("findALL");
    }

    private void save(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("save");
    }

    private void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("update");
    }
}
